package com.aaa.controller.api;

import com.aaa.aop.annotation.Log;
import com.aaa.entity.Dept;
import com.aaa.entity.Menu;
import com.aaa.entity.User;
import com.aaa.service.MenuService;
import com.aaa.service.impl.MenuServiceImpl;
import com.aaa.vo.MenuVo;
import com.aaa.vo.Result;
import com.aaa.vo.UserVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import net.bytebuddy.implementation.bind.annotation.Origin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/api/menu")
@CrossOrigin
public class MenuControllerApi {
    @Autowired
    private MenuServiceImpl menuService;
    @GetMapping("/leftMenu")
    public Result<List<Menu>> leftMenun(){
        return menuService.getLeftMenu();
    }

    @GetMapping("/list")
    public Result<List<Menu>> list(){
        return menuService.getAll();
    }

    @GetMapping("findByRoleId/{roleId}")
    public Result<List<Integer>> findByRoleId(@PathVariable Long roleId){
        return menuService.findByRoleId(roleId);
    }

    @PostMapping("confirmMenu")
    @Log(title = "确认分配权限",business_type = "系统业务")
    public Result<String> confirmMenu(Long roleId,Long[] menuIds){
        return menuService.confirmMenu(roleId,menuIds);
    }

    @PostMapping("searchMenu/{currentPage}/{pageSize}")
    public Result<IPage<Menu>> searchMenu(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody MenuVo menuVo){
        return menuService.MenuPage(currentPage, pageSize, menuVo);
    }
    //添加修改
    @PostMapping("saveAndUpdate")
    public Result saveAndUpdate(Menu menu) {
        if (menuService.saveAndUpdate(menu)) {
            return new Result(200, "操作成功", true);
        } else {
            return new Result(500, "操作失败", false);
        }
    }


    //删除
    @DeleteMapping("delById/{id}")
    public Result delById(@PathVariable Long id){
        if (menuService.delById(id)){
            return new Result(200,"修改成功",true);
        }else {
            return  new Result(500,"修改失败",false);
        }
    }


}
